package com.group9.handinhand.controller.form;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import com.group9.handinhand.service.so.CommunityMemberSO;
import com.group9.handinhand.service.so.OfferPostSO;
import com.group9.handinhand.service.so.OfferResponseSO;
import com.group9.handinhand.service.so.OfferSO;
import com.group9.handinhand.service.so.UserTagSO;

public class OfferViewForm {
	
	OfferSO offer;
	OfferSO moderatedOffer;
	CommunityMemberSO communityMember;
	String post;
	int goodsAmount;
	int servicesAmount;
	int userContribution;
	ArrayList<Object> wallElements = new ArrayList<Object>();
	List<UserTagSO> userTags;
	ArrayList<Object> offerList;

	/**
	 * A set method.
	 * Sets the elements in the offer wall to the offer.
	 */

	public void setWallElementsFromOffer(){
		wallElements.addAll(offer.getPosts());
		Collections.sort(wallElements, new Comparator<Object>() {
			
			public int compare(Object o1, Object o2) {
				Date o1createDate = ((OfferPostSO)o1).getCreateDate();
						
				Date o2createDate = ((OfferPostSO)o2).getCreateDate();
				if (o1createDate == null || o2createDate == null)
					return 0;
				return o2createDate.compareTo(o1createDate);
			}
		});

	}
	/**
	 * A getter method.
	 * @return moderatedOffer
	 */
	public OfferSO getModeratedOffer() {
		return moderatedOffer;
	}
	/**
	 * A setter method.
	 * 
	 * @param moderatedOffer
	 */
	public void setModeratedOffer(OfferSO moderatedOffer) {
		this.moderatedOffer = moderatedOffer;
	}
	/**
	 * A getter method.
	 * @return communityMember
	 */
	public CommunityMemberSO getCommunityMember() {
		return communityMember;
	}
	/**
	 * A set community
	 * @param communityMember
	 */
	public void setCommunityMember(CommunityMemberSO communityMember) {
		this.communityMember = communityMember;
	}
	/**
	 * A getter method.
	 * @return the list of wall elements as an arraylist
	 */
	public ArrayList<Object> getWallElements() {
		return wallElements;
	}
	/**
	 * A setter method.
	 * @param wallElements
	 */
	public void setWallElements(ArrayList<Object> wallElements) {
		this.wallElements = wallElements;
	}
	/**
	 * A getter method.
	 * @return offer
	 */
	public OfferSO getOffer() {
		return offer;
	}
	/**
	 * A setter method.
	 * @param offer
	 */
	public void setOffer(OfferSO offer) {
		this.offer = offer;
	}
	/**
	 * A getter method.
	 * @return post
	 */
	public String getPost() {
		return post;
	}
	/**
	 * A setter method.
	 * @param post
	 */
	public void setPost(String post) {
		this.post = post;
	}
	/**
	 * A getter method.
	 * @return the amounts of the goods
	 */
	public int getGoodsAmount() {
		return goodsAmount;
	}
	/**
	 * A setter method.
	 * @param goodsAmount
	 */
	public void setGoodsAmount(int goodsAmount) {
		this.goodsAmount = goodsAmount;
	}
	/**
	 * A getter method
	 * @return the amount of the service
	 */
	public int getServicesAmount() {
		return servicesAmount;
	}
	/**
	 * A setter method.
	 * @param servicesAmount
	 */
	public void setServicesAmount(int servicesAmount) {
		this.servicesAmount = servicesAmount;
	}
	/**
	 * A getter method.
	 * @return userContribution
	 */
	public int getUserContribution() {
		return userContribution;
	}
	/**
	 * A setter method.
	 * @param userContribution
	 */
	public void setUserContribution(int userContribution) {
		this.userContribution = userContribution;
	}
	/**
	 * A set method.
	 * @param list
	 */
	public void setUserContributionFromList(ArrayList<OfferResponseSO> list){
		userContribution = 0;
		for (OfferResponseSO offerResponseSO : list) {
			userContribution += offerResponseSO.getRespondAmount();
		}
	}
	/**
	 * A getter methods.
	 * @return the list of tags of the user
	 */
	public List<UserTagSO> getUserTags() {
		return userTags;
	}
	/**
	 * A setter method
	 * @param userTags
	 */
	public void setUserTags(List<UserTagSO> userTags) {
		this.userTags = userTags;
	}
	/**
	 * A getter method 
	 * @return the list of offer as an array list.
	 */
	public ArrayList<Object> getOfferList() {
		return offerList;
	}
	/**
	 * A setter method.
	 * @param offerList
	 */
	public void setOfferList(ArrayList<Object> offerList) {
		this.offerList = offerList;
	}

	/**
	 * To string method which converts the offer form into string.
	 */
	@Override
	public String toString() {
		return "OfferViewForm [offer=" + offer + ", post=" + post
				+ ", goodsAmount=" + goodsAmount + ", servicesAmount="
				+ servicesAmount + ", userContribution=" + userContribution
				+ ", wallElements=" + wallElements + "]";
	}

}
